package scr 
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import ru.gosoplata.events.NextEvent;
	import ru.gosoplata.model.TmpModel;
	import ru.gosoplata.view.CoinOutMediator;
	import ru.gosoplata.view.ICoinOut;
	import uicontrols.ButtonBase;
	/**
	 * ...
	 * @author a.orleansky
	 */
	public class ScreenCoinOUT extends ScreenBase implements ICoinOut, IScreen 
	{
		[Event(name = "next", type = "ru.gosoplata.events.NextEvent")]
		
		private var _infoTxt:TextField;
		private var _btnNext:ButtonBase = new ButtonBase("next");
		
		private var _mediator:CoinOutMediator;
		
		public function set infoText(str:String):void 
		{
			_infoTxt.text=str;
		}
		
		public function set nextBtnVisible(value:Boolean):void 
		{
			_btnNext.visible = value;
		}
		
		public function ScreenCoinOUT() 
		{
			super("coinout");
			_mediator = new CoinOutMediator(this);
		}
		
		override public function reDraw():void
		{
			_mediator.reDraw();
		}
		
		override protected function init(e:Event):void 
		{
			super.init(e);
			
			_infoTxt = new TextField();
			_infoTxt.embedFonts = true;
			_infoTxt.defaultTextFormat = TmpModel.getTextFormat(30, 0x838383,true);
			_infoTxt.width = 900;
			_infoTxt.selectable = false;
			
			_btnNext.addEventListener(ButtonBase.ON_PIC_LOADED, allPicLoaded);
			_btnNext.addEventListener(ButtonBase.ON_PRESS_UI_BUTTON, onNextBtn);
			addChild(_btnNext);
		}	
		
		private function onNextBtn(e:Event):void 
		{
			dispatchEvent(new NextEvent());
		}
		
		private function allPicLoaded(e:Event):void 
		{
			_btnNext.x = stage.stageWidth - (_btnNext.width + 60);
			_btnNext.y = stage.stageHeight - (_btnNext.height + 20);
			
			var image:Loader = new Loader();
			var url:URLRequest = new URLRequest("img/blagorim_za_ispolzovanie/images/plane_big_platezi.png");
			image.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void { } );
			image.load(url);
			image.x = 130;
			image.y = 230;
			addChild(image);
			
			_infoTxt.x = image.x + 200;
			_infoTxt.y = image.y+200;
			addChild(_infoTxt);
			
			loadBanner(TmpModel.IMG_FOLDER + "/blagorim_za_ispolzovanie/images/tualet_zanyat_title.png");
		}
	}
}